<?php
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Special\Controller;
use \Common\Controller\BaseController;
/* 专题前台浏览 */
class IndexController extends BaseController 
{
	public function _initialize() {
		parent::_initialize();
		$this->db = D('Special');
		$this->special_db = D('SpecialContent');
	}

	/* 专题首页 */
	public function init() {
		include template($template, 'special');
	}

	/* 专题列表页 */
	public function lists() {
		$pagecurr = max(1,I('page',0,'intval'));
		$pagesize = 32;
		$sqlMap = array();
		$special_count = $this->db->where($sqlMap)->count();
		$special_lists = $this->db->where($sqlMap)->page($pagecurr,$pagesize)->order('createtime DESC')->select();
		$pages = page($special_count,$pagesize);
		include template('list');
	}

	/* 专题展示 */
	public function show() {
		$id = (int) I('id');
		$special_count = $this->special_db->where(array('specialid'=>$id))->count();
		$special_content = $this->special_db->where(array('specialid'=>$id))->select();
		//根据specialid查出专题名称
		foreach($special_content as $key=>$val){
				$special_content[$key]['special_title'] = $this->db->getFieldById($id,'title');		
		}
		//上一个专题
		$special_prev = $this->db->where(array('id'=>array('lt',$id)))->order('id DESC')->find();
		//下一个专题
		$special_next = $this->db->where(array('id'=>array('gt',$id)))->order('id ASC')->find();
		
		//推荐标题
		$special_lists = $this->db->where(array('elite'=>1))->limit(4)->select();
		$rs = D('Sucai')->order('rand() and inputtime DESC')->limit(8)->select();
		//echo D('Sucai')->getLastSql();
		include template('show');
	}
	/*换一换*/
	public function change(){
		$tm = I('tm');
		if($tm == 1){
			$rs = $this->db->order('rand()')->limit(4)->select();
		}else if($tm == 2){
			$rs = $this->db->where(array('elite'=>1))->order('rand()')->limit(4)->select();
		}else{//新图上架
			$rs = D('Sucai')->order('rand()')->limit(8)->select();
		}
		echo json_encode($rs);
	}
}